package com.wxl.common.base

import android.os.Build
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import com.wxl.common.util.KeyBoardUtil


/**
 * create file time : 2021/3/1
 * create user : wxl
 * subscribe :
 */
abstract class AbsActivity : AppCompatActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setWindowStatusBar()
        setContentView(getCreateContentViewId())
        onCreateViewChanged()
    }


    abstract fun getCreateContentViewId():Int


    abstract fun onCreateViewChanged()


    internal fun setWindowStatusBar(){
        //状态栏透明化: 侵入式透明status bar
        //状态栏透明化: 侵入式透明status bar
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            val window: Window = window
            // Translucent status bar
            window.setFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
            )
        }
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        KeyBoardUtil.hideSoftInput(window.decorView)
        KeyBoardUtil.releaseObserver(this)
    }
}